#!/bin/bash
options=()
eoo=0

while [[ $1 ]]
do
    if ! ((eoo)); then
    case "$1" in
        -D__GNUC__=*)
            shift
            ;;
        -D__GNUC__)
            shift
            ;;
        -D__GNUG__=*)
            shift
            ;;
        -D__GNUG__)
            shift
            ;;
        -D)
            case "$2" in
                  __GNUC__=*)
                        shift
                        ;;
                  __GNUC__)
                        shift
                        ;;
                  __GNUG__=*)
                        shift
                        ;;
                  __GNUG__)
                        shift
                        ;;
                  *)
                        options+=("$1" "$2")
                        shift
                        ;;
            esac
            shift
            ;;
        -std=*)
            shift
            ;;
        --)
            eoo=1
            options+=("$1")
            shift
            ;;
        *)
            options+=("$1")
            shift
            ;;
      esac
    else
      options+=("$1")
      shift
    fi
done

standard="c++14"
if (g++ -std=c++14 |& grep -q unrecognized); then
  standard="c++11"
fi

g++ -Wall -Wextra -x c++ -std=$standard -nostdlib \
      -U __GNUC__ -U __GNUG__ -D__KCC__ \
      -include "$(dirname "$0")/include/kcc_settings.h" \
      -E -I "$(dirname "$0")/include/library" "${options[@]}"
